package com.vcredit.creditcat.service.product;

import java.net.URLEncoder;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.vcredit.creditcat.service.product.util.RSAUtils;
import com.vcredit.creditcat.util.Constants;

@Service
public class KKDH5UrlService {
  
  @Value("${kkd.base.url}")
  private String BASE_URL;
  @Value("${kkd.sign.pirvateKey}")
  private String SIGN_PIRVATE_KEY;
  @Value("${kkd.init.url}")
  private String KKD_INIT_URL;
      

  public String getH5Url(Long custId) {
    String initUrl = null;
    long timestamp = System.currentTimeMillis();
    String custUUID = Constants.PROJECT_PREFIX + custId;
    String signature = custUUID + Constants.KAK_SUBMIT_ACCOUNT + timestamp;
    try {
      signature = RSAUtils.sign(signature.getBytes("utf-8"), SIGN_PIRVATE_KEY);
      signature = URLEncoder.encode(signature, "utf-8");
      initUrl = BASE_URL + String.format(KKD_INIT_URL, custUUID, Constants.KAK_SUBMIT_ACCOUNT, timestamp, signature);
    } catch (Exception e) {}
    return initUrl;
  }
}
